#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		long long  a1,k;
		scanf("%lld %lld",&a1,&k);
		for(int i = 1;i<k;i++)
		{
			long long n = a1;
			long long minn = 10;
			long long maxx = -1;
			while(n)
			{
				long long t = n%10;
				n = n/10;
				minn = min(minn,t);
				maxx = max(maxx,t); 
			}
			a1 = a1+(minn*maxx);
			if(minn==0) break;
		//	printf("***%d %d %d\n",a1,minn,maxx);
		}
		printf("%lld\n",a1);
	}
} 
